package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.MemberService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.MemberDto;
import com.huilian.iotbox.data.enums.ErrorMsgEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("/api/member")
public class MemberController extends UserInfoController {
    @Resource
    private MemberService memberService;


    /**
     * 公众号-兑换商城推送礼品的通知记录
     *
     * @param memberDto
     * @param request
     * @return
     */
    @PostMapping("/findList")
    public ServerResponse findAllMemberByCondition(@RequestBody MemberDto memberDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        memberDto.setUserInfo(userInfo);
        return memberService.findList(memberDto);
    }

    @PostMapping("/getStatsData")
    public ServerResponse getStatsData(@RequestBody MemberDto memberDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        memberDto.setUserInfo(userInfo);
        return memberService.getMemberStatsData(memberDto);
    }

    @PostMapping("/findStatsGroupByStore")
    public ServerResponse findStatsGroupByStore(@RequestBody MemberDto memberDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        memberDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(memberService.findStatsGroupByStore(memberDto));
    }

    @PostMapping("/findByStoreId")
    public ServerResponse findByStoreId(@RequestBody MemberDto memberDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        memberDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(memberService.findByStoreId(memberDto));
    }

    @PostMapping("/findByMemberIdMerchantStoreId")
    public ServerResponse findById(@RequestBody MemberDto memberDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        memberDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(memberService.findByMemberIdMerchantStoreId(memberDto));
    }

    @PostMapping("/findMultiConditionPayCoins")
    public ServerResponse findMultiConditionPayCoins(@RequestBody MemberDto memberDto,HttpServletRequest request){
        UserInfo userInfo = super.getLoginUserInfo(request);
        memberDto.setUserInfo(userInfo);
        return memberService.findMultiConditionPayCoins(memberDto,request);
    }

    @PostMapping("/findByMerchantStoreId")
    public ServerResponse findByMerchantStoreId(@RequestBody MemberDto memberDto,HttpServletRequest request){
        UserInfo userInfo = super.getLoginUserInfo(request);
        memberDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(memberService.findByMerchantStoreId(memberDto));
    }
}
